﻿singleApp.controller('adminLoginCtrl', ['$http', '$scope', function ($http, $scope) {
	$scope.vm = {
	    phone: "",
		password: "",
	};

	$scope.submit = function () {
	    if ($scope.vm.phone == undefined || $scope.vm.phone == "") {
			layer.msg("请输入11位手机号 !");
			return;
		}
		if ($scope.vm.password == undefined || $scope.vm.password == "") {
			layer.msg("请输入密码 !");
			return;
		}

		var api_url = window.singleConfig.rootUrl + 'api/user/AuthService/loginAdminPost';
		layer.load(2);
		$http({
			method: 'POST',
			url: api_url,
			data: $.param($scope.vm),
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
		})
		.then(function (result) {
			var data = result.data;
			if (data.code == "success") {
				layer.closeAll();
				location.href = data.redirectUrl;
			}
			else {
				layer.closeAll();		    
				layer.msg(data.message);
			}
		},function (data) {		
			layer.msg("用户名或者密码错误!");
		});	
	}


}]);